{include file="public/head"}

<body>
<section class="content">
    <header>
        <span><a href="javascript:history.go(-1)"><img src="__STATIC__/User/img/Return.png" alt=""></a></span>
        <p>理财详情</p>
        <span></span>
    </header>

    <div class="cunkuan">
        <div class="level">
            <input type="hidden" id="id" value="{$DepositDetail.id}">
            <p>剩余金额</p>
            <input class="dengji" type="text" value="{$DepositDetail.surplus_num}" readonly />
            <p>取出金额</p>
            <input class="dengji" id="num" type="text" placeholder="请输入取出金额" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" />
            <p>手机验证码</p>
            <div class="getCode">
                <input type="text" id="code" placeholder="请输入验证码" class="dengji"><span id="send">获取验证码</span>
            </div>
            <div class="btnbox">
                {if condition="$DepositDetail.BackStatus eq 1"}
                <div class="sub" id="back">理财赎回</div>
                {/if}
<!--                {if condition="$DepositDetail.GetStatus eq 1"}-->
<!--                <div class="sub" id="get">到期取本</div>-->
<!--                {/if}-->
                <div class="sub" id="release">溢出赎回</div>
            </div>
        </div>

        <div class="level record">
            <ul class="top">
                <li>
                    <span>金额</span>
                    <span>时间</span>
                    <span>类型</span>
                </li>
            </ul>
            <ul class="content" style="height: 3rem">
                {volist name="FinanceList" id="v"}
                <li>
                    <span>{$v.num}</span>
                    <span>{$v.add_time|date="m/d H:i",###}</span>
                    <span>{$v.remarks}</span>
                </li>
                {/volist}
            </ul>
        </div>
    </div>
</section>

<script src="__STATIC__/User/js/jquery-2.1.1.min.js"></script>
<script>
    var flag1 = true;
    //发送验证吗
    $("#send").on('click',function(){
        if(flag1) {
            flag1 = false
            var phone = "{$UserInfo.phone}";
            $.ajax({
                type:"POST",
                url:"{:url('Open/SendCode')}",
                data:{
                    phone:phone,
                },
                dataType:"json",
                success:function(data){
                    console.log(data)
                    if(data.status == 1){
                        alert(data.message);
                        var time = 60;
                        var interval = setInterval(function(){
                            time -= 1;
                            $("#send").text(`剩余时间${time}`);
                            if(time == 0){
                                clearInterval(interval)
                                $("#send").text('重新发送');
                                flag1 = true
                            }
                        },1000)
                    }else{
                        alert(data.message);
                    }
                }
            });
        }
    })

    //提交申请
    $("#back").on('click',function(){   //定存退本
        if(confirm('可退出金额为（定存总额 - 每天已领取收益）* 50% ， 确认退本吗？')){
            var id = $("#id").val();
            var cycle = $("#cycle").val();
            var code = $("#code").val();
            var type = "back";

            if(code == ""){
                alert('请输入验证码');
                return false;
            }

            $.ajax({
                type:"POST",
                url:"{:url('Finance/DepositReduce')}",
                data:{
                    id:id,
                    code:code,
                    type:type,
                },
                dataType: "json",
                success:function(data){
                    if(data.status == 1){
                        alert(data.message);
                        window.location.reload();
                    }else{
                        alert(data.message);
                    }
                }
            })
        }
    })

    //提交申请
    $("#release").on('click',function(){   //释放退本
        if(confirm('赎回将减少您的收益，确定赎回吗？')){
            var id = $("#id").val();
            var num = $("#num").val();
            var code = $("#code").val();
            var type = "release";

            if(num == ""){
                alert('请输入取出金额');
                return false;
            }

            if(code == ""){
                alert('请输入验证码');
                return false;
            }

            $.ajax({
                type:"POST",
                url:"{:url('Finance/DepositReduce')}",
                data:{
                    id:id,
                    num:num,
                    code:code,
                    type:type,
                },
                dataType: "json",
                success:function(data){
                    if(data.status == 1){
                        alert(data.message);
                        window.location.reload();
                    }else{
                        alert(data.message);
                    }
                }
            })
        }
    })

    //提交申请
    $("#get").on('click',function(){   //释放退本
        if(confirm('赎回将减少您的收益，确定赎回吗？')){
            var id = $("#id").val();
            var num = $("#num").val();
            var code = $("#code").val();
            var type = "get";

            if(num == ""){
                alert('请输入取出金额');
                return false;
            }

            if(code == ""){
                alert('请输入验证码');
                return false;
            }

            $.ajax({
                type:"POST",
                url:"{:url('Finance/DepositReduce')}",
                data:{
                    id:id,
                    num:num,
                    code:code,
                    type:type,
                },
                dataType: "json",
                success:function(data){
                    if(data.status == 1){
                        alert(data.message);
                        window.location.reload();
                    }else{
                        alert(data.message);
                    }
                }
            })
        }
    })

</script>
</body>
</html>